home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / msdos / css / source / calc.c next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  22.6 KB  |  650 lines

  1.  
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <glib.h>
  6. #include "land.h"
  7.  
  8.  /* #include "..\lib.h" */
  9.  
  10. /* math error no. */
  11. int mathern;
  12.  
  13. /*
  14. int matherr(x)
  15. struct exception *x;
  16. {
  17.    mathern = x->type+1000;
  18.    return(1);
  19. }
  20. */
  21.  
  22. void  mcu1()
  23. {
  24. int     xpnt, ypnt;
  25. MOS_CUS cus;
  26.  
  27.    xpnt = 0; ypnt = 0;
  28.    cus.xcnt = 16; cus.ycnt = 16;
  29.    cus.color = col15;
  30.    cus.type[0]  = 0x8f; cus.type[1]  = 0xff;
  31.    cus.type[2]  = 0x07; cus.type[3]  = 0xff;
  32.    cus.type[4]  = 0x03; cus.type[5]  = 0xff;
  33.    cus.type[6]  = 0x81; cus.type[7]  = 0xff;
  34.    cus.type[8]  = 0xc0; cus.type[9]  = 0x03;
  35.    cus.type[10] = 0xe0; cus.type[11] = 0x01;
  36.    cus.type[12] = 0xf0; cus.type[13] = 0x00;
  37.    cus.type[14] = 0xf0; cus.type[15] = 0x00;
  38.    cus.type[16] = 0xe0; cus.type[17] = 0x00;
  39.    cus.type[18] = 0xe0; cus.type[19] = 0x00;
  40.    cus.type[20] = 0xe0; cus.type[21] = 0x00;
  41.    cus.type[22] = 0xe0; cus.type[23] = 0x00;
  42.    cus.type[24] = 0xf0; cus.type[25] = 0x01;
  43.    cus.type[26] = 0xf8; cus.type[27] = 0x01;
  44.    cus.type[28] = 0xfc; cus.type[29] = 0x03;
  45.    cus.type[30] = 0xfe; cus.type[31] = 0x0f;
  46.  
  47.    cus.type[32] = 0x00; cus.type[33] = 0x00;
  48.    cus.type[34] = 0x70; cus.type[35] = 0x00;
  49.    cus.type[36] = 0x78; cus.type[37] = 0x00;
  50.    cus.type[38] = 0x3c; cus.type[39] = 0x00;
  51.    cus.type[40] = 0x1e; cus.type[41] = 0x00;
  52.    cus.type[42] = 0x0f; cus.type[43] = 0xfc;
  53.    cus.type[44] = 0x07; cus.type[45] = 0xfe;
  54.    cus.type[46] = 0x07; cus.type[47] = 0xfe;
  55.    cus.type[48] = 0x0f; cus.type[49] = 0xfe;
  56.    cus.type[50] = 0x0f; cus.type[51] = 0xfe;
  57.    cus.type[52] = 0x0f; cus.type[53] = 0xfe;
  58.    cus.type[54] = 0x0f; cus.type[55] = 0xfe;
  59.    cus.type[56] = 0x07; cus.type[57] = 0xfc;
  60.    cus.type[58] = 0x03; cus.type[59] = 0xfc;
  61.    cus.type[60] = 0x01; cus.type[61] = 0xf0;
  62.    cus.type[62] = 0x00; cus.type[63] = 0x00;
  63.  
  64.    MOS_type(xpnt, ypnt, &cus);
  65. }
  66.  
  67. void  mcu2()
  68. {
  69. int     xpnt, ypnt;
  70. MOS_CUS cus;
  71.  
  72.    xpnt = 0; ypnt = 4;
  73.    cus.xcnt = 16; cus.ycnt = 16;
  74.    cus.color = col15;
  75.    cus.type[0]  = 0xc0; cus.type[1]  = 0x3f;
  76.    cus.type[2]  = 0x80; cus.type[3]  = 0x0f;
  77.    cus.type[4]  = 0x00; cus.type[5]  = 0x03;
  78.    cus.type[6]  = 0x1e; cus.type[7]  = 0x01;
  79.    cus.type[8]  = 0xff; cus.type[9]  = 0x01;
  80.    cus.type[10] = 0x1f; cus.type[11] = 0x00;
  81.    cus.type[12] = 0x00; cus.type[13] = 0x00;
  82.    cus.type[14] = 0x00; cus.type[15] = 0x00;
  83.    cus.type[16] = 0x80; cus.type[17] = 0x00;
  84.    cus.type[18] = 0xe0; cus.type[19] = 0x00;
  85.    cus.type[20] = 0xfc; cus.type[21] = 0x00;
  86.    cus.type[22] = 0xfe; cus.type[23] = 0x00;
  87.    cus.type[24] = 0xff; cus.type[25] = 0x00;
  88.    cus.type[26] = 0xff; cus.type[27] = 0x00;
  89.    cus.type[28] = 0xff; cus.type[29] = 0x81;
  90.    cus.type[30] = 0xff; cus.type[31] = 0xc3;
  91.  
  92.    cus.type[32] = 0x00; cus.type[33] = 0x00;
  93.    cus.type[34] = 0x3f; cus.type[35] = 0xc0;
  94.    cus.type[36] = 0x61; cus.type[37] = 0xf0;
  95.    cus.type[38] = 0x00; cus.type[39] = 0x7c;
  96.    cus.type[40] = 0x00; cus.type[41] = 0x7c;
  97.    cus.type[42] = 0x00; cus.type[43] = 0x7e;
  98.    cus.type[44] = 0x60; cus.type[45] = 0xfe;
  99.    cus.type[46] = 0x7f; cus.type[47] = 0xfe;
  100.    cus.type[48] = 0x1f; cus.type[49] = 0xfe;
  101.    cus.type[50] = 0x03; cus.type[51] = 0xfe;
  102.    cus.type[52] = 0x01; cus.type[53] = 0xfe;
  103.    cus.type[54] = 0x00; cus.type[55] = 0xfe;
  104.    cus.type[56] = 0x00; cus.type[57] = 0x7e;
  105.    cus.type[58] = 0x00; cus.type[59] = 0x7e;
  106.    cus.type[60] = 0x00; cus.type[61] = 0x3c;
  107.    cus.type[62] = 0x00; cus.type[63] = 0x00;
  108.  
  109.    MOS_type(xpnt, ypnt, &cus);
  110. }
  111.  
  112.  
  113. void  mcu3()
  114. {
  115. int     xpnt, ypnt;
  116. MOS_CUS cus;
  117.  
  118.    xpnt = 7; ypnt = 7;
  119.    cus.xcnt = 16; cus.ycnt = 16;
  120.    cus.color = col15;
  121.    cus.type[0]  = 0xfc; cus.type[1]  = 0x3f;
  122.    cus.type[2]  = 0xf0; cus.type[3]  = 0x07;
  123.    cus.type[4]  = 0xf0; cus.type[5]  = 0x07;
  124.    cus.type[6]  = 0xf0; cus.type[7]  = 0x03;
  125.    cus.type[8]  = 0xf0; cus.type[9]  = 0x03;
  126.    cus.type[10] = 0xf0; cus.type[11] = 0x01;
  127.    cus.type[12] = 0x80; cus.type[13] = 0x01;
  128.    cus.type[14] = 0x80; cus.type[15] = 0x00;
  129.    cus.type[16] = 0x80; cus.type[17] = 0x00;
  130.    cus.type[18] = 0x80; cus.type[19] = 0x01;
  131.    cus.type[20] = 0x80; cus.type[21] = 0x01;
  132.    cus.type[22] = 0xc0; cus.type[23] = 0x03;
  133.    cus.type[24] = 0xc0; cus.type[25] = 0x07;
  134.    cus.type[26] = 0xe0; cus.type[27] = 0x07;
  135.    cus.type[28] = 0xf0; cus.type[29] = 0x0f;
  136.    cus.type[30] = 0xf0; cus.type[31] = 0x0f;
  137.  
  138.    cus.type[32] = 0x00; cus.type[33] = 0x00;
  139.    cus.type[34] = 0x03; cus.type[35] = 0xc0;
  140.    cus.type[36] = 0x07; cus.type[37] = 0xf0;
  141.    cus.type[38] = 0x07; cus.type[39] = 0xf8;
  142.    cus.type[40] = 0x07; cus.type[41] = 0xf8;
  143.    cus.type[42] = 0x07; cus.type[43] = 0xfc;
  144.    cus.type[44] = 0x07; cus.type[45] = 0xfc;
  145.    cus.type[46] = 0x3f; cus.type[47] = 0xfe;
  146.    cus.type[48] = 0x3f; cus.type[49] = 0xfe;
  147.    cus.type[50] = 0x3f; cus.type[51] = 0xfc;
  148.    cus.type[52] = 0x3f; cus.type[53] = 0xfc;
  149.    cus.type[54] = 0x1f; cus.type[55] = 0xf8;
  150.    cus.type[56] = 0x1f; cus.type[57] = 0xf0;
  151.    cus.type[58] = 0x0f; cus.type[59] = 0xf0;
  152.    cus.type[60] = 0x07; cus.type[61] = 0xe0;
  153.    cus.type[62] = 0x00; cus.type[63] = 0x00;
  154.  
  155.    MOS_type(xpnt, ypnt, &cus);
  156. }
  157.  
  158. void  mcu4()
  159. {
  160. int     xpnt, ypnt;
  161. MOS_CUS cus;
  162.  
  163.    xpnt = 7; ypnt = 7;
  164.    cus.xcnt = 16; cus.ycnt = 16;
  165.    cus.color = col15;
  166.    cus.type[0]  = 0xfe; cus.type[1]  = 0xff;
  167.    cus.type[2]  = 0xfe; cus.type[3]  = 0xff;
  168.    cus.type[4]  = 0xfe; cus.type[5]  = 0xff;
  169.    cus.type[6]  = 0xfe; cus.type[7]  = 0xff;
  170.    cus.type[8]  = 0xfe; cus.type[9]  = 0xff;
  171.    cus.type[10] = 0xfe; cus.type[11] = 0xff;
  172.    cus.type[12] = 0xfe; cus.type[13] = 0xff;
  173.    cus.type[14] = 0x03; cus.type[15] = 0x81;
  174.    cus.type[16] = 0xfe; cus.type[17] = 0xff;
  175.    cus.type[18] = 0xfe; cus.type[19] = 0xff;
  176.    cus.type[20] = 0xfe; cus.type[21] = 0xff;
  177.    cus.type[22] = 0xfe; cus.type[23] = 0xff;
  178.    cus.type[24] = 0xfe; cus.type[25] = 0xff;
  179.    cus.type[26] = 0xfe; cus.type[27] = 0xff;
  180.    cus.type[28] = 0xfe; cus.type[29] = 0xff;
  181.    cus.type[30] = 0xff; cus.type[31] = 0xff;
  182.  
  183.    cus.type[32] = 0x01; cus.type[33] = 0x00;
  184.    cus.type[34] = 0x01; cus.type[35] = 0x00;
  185.    cus.type[36] = 0x01; cus.type[37] = 0x00;
  186.    cus.type[38] = 0x01; cus.type[39] = 0x00;
  187.    cus.type[40] = 0x01; cus.type[41] = 0x00;
  188.    cus.type[42] = 0x01; cus.type[43] = 0x00;
  189.    cus.type[44] = 0x00; cus.type[45] = 0x00;
  190.    cus.type[46] = 0xfc; cus.type[47] = 0x7e;
  191.    cus.type[48] = 0x00; cus.type[49] = 0x00;
  192.    cus.type[50] = 0x01; cus.type[51] = 0x00;
  193.    cus.type[52] = 0x01; cus.type[53] = 0x00;
  194.    cus.type[54] = 0x01; cus.type[55] = 0x00;
  195.    cus.type[56] = 0x01; cus.type[57] = 0x00;
  196.    cus.type[58] = 0x01; cus.type[59] = 0x00;
  197.    cus.type[60] = 0x01; cus.type[61] = 0x00;
  198.    cus.type[62] = 0x00; cus.type[63] = 0x00;
  199.  
  200.    MOS_type(xpnt, ypnt, &cus);
  201. }
  202.  
  203. void calcu(int x, int y, int sw)
  204. {
  205.     unsigned  ddadr[2];
  206.     unsigned char page = 0;
  207.     char      buf[32]; /* (16*16+7)/8 */
  208.     int c1, c2, c3, c4;
  209.  
  210.     buf[0]=0xff;  buf[1]=0xfe;  buf[2]=0x80;  buf[3]=0x02;  buf[4]=0xbf;  buf[5]=0xda;  buf[6]=0xbf;  buf[7]=0xda;
  211.     buf[8]=0xbf;  buf[9]=0xda;  buf[10]=0x80; buf[11]=0x02; buf[12]=0xb6; buf[13]=0xda; buf[14]=0xb6; buf[15]=0xda;
  212.     buf[16]=0x80; buf[17]=0x02; buf[18]=0xb6; buf[19]=0xda; buf[20]=0xb6; buf[21]=0xda; buf[22]=0x80; buf[23]=0x02;
  213.     buf[24]=0xb6; buf[25]=0xda; buf[26]=0xb6; buf[27]=0xda; buf[28]=0x80; buf[29]=0x02; buf[30]=0xff; buf[31]=0xfe;
  214.     
  215.     if (sw == 0) {
  216.        c1 = col0; c2 = col7; c3 = col8; c4 = col1;
  217.     } else {
  218.        c1 = col0; c2 = col8; c3 = col15; c4 = col15;
  219.     }
  220.     line(x+2, y+2, x+21, y+21, PSET, c1, 2, 0xffff);
  221.     line(x, y, x+19, y+19, PSET, c2, 2, 0xffff);
  222.     line(x, y, x+19, y+19, PSET, c3, 1, 0xffff);
  223.     BSETDATAADR(ddadr, buf);
  224.     GDS_putBlockColor(ddadr[0], ddadr[1], page, x+2, y+2, x+17, y+17, c4, PSET);
  225. }
  226.  
  227. /* *x0, *y0 = 左上座標  xsiz, ysiz = ボックスの大きさ  xpos, ypos = 左上座標からのカーソルの位置差 */
  228. void movbox(int *x0, int *y0, int xsiz, int ysiz, int xpos, int ypos)
  229. {
  230. int wx, wy, x, y;
  231. char buf1x[323], buf2x[323], buf1y[203], buf2y[203]; /* (640*1+7)/8*4,  (400*1+7)/8*4  */
  232. unsigned  ddadr1x[2], ddadr2x[2], ddadr1y[2], ddadr2y[2];
  233. unsigned char page = 0;
  234.  
  235.    x = *x0; y = *y0;
  236.    BSETDATAADR(ddadr1x, buf1x);
  237.    BSETDATAADR(ddadr2x, buf2x);
  238.    BSETDATAADR(ddadr1y, buf1y);
  239.    BSETDATAADR(ddadr2y, buf2y);
  240.  
  241.    GDS_getBlock(ddadr1x[0], ddadr1x[1], page, x, y, x+xsiz-1, y);
  242.    GDS_getBlock(ddadr2x[0], ddadr2x[1], page, x, y+ysiz-1, x+xsiz-1, y+ysiz-1);
  243.    GDS_getBlock(ddadr1y[0], ddadr1y[1], page, x, y+1, x, y+ysiz-2);
  244.    GDS_getBlock(ddadr2y[0], ddadr2y[1], page, x+xsiz-1, y+1, x+xsiz-1, y+ysiz-2);
  245.    line(x, y, x+xsiz-1, y+ysiz-1, PSET, col8, 1, 0xffff);
  246.  
  247.    while ((MOS_rdpos(&wx, &wy) & 0x01) == 1) {
  248.       if (wx-xpos != x || wy-ypos != y) {
  249.          GDS_putBlock(ddadr1x[0], ddadr1x[1], page, x, y, x+xsiz-1, y, PSET);
  250.          GDS_putBlock(ddadr2x[0], ddadr2x[1], page, x, y+ysiz-1, x+xsiz-1, y+ysiz-1, PSET);
  251.          GDS_putBlock(ddadr1y[0], ddadr1y[1], page, x, y+1, x, y+ysiz-2, PSET);
  252.          GDS_putBlock(ddadr2y[0], ddadr2y[1], page, x+xsiz-1, y+1, x+xsiz-1, y+ysiz-2, PSET);
  253.          x = wx-xpos, y = wy-ypos;
  254.          GDS_getBlock(ddadr1x[0], ddadr1x[1], page, x, y, x+xsiz-1, y);
  255.          GDS_getBlock(ddadr2x[0], ddadr2x[1], page, x, y+ysiz-1, x+xsiz-1, y+ysiz-1);
  256.          GDS_getBlock(ddadr1y[0], ddadr1y[1], page, x, y+1, x, y+ysiz-2);
  257.          GDS_getBlock(ddadr2y[0], ddadr2y[1], page, x+xsiz-1, y+1, x+xsiz-1, y+ysiz-2);
  258.          line(x, y, x+xsiz-1, y+ysiz-1, PSET, col8, 1, 0xffff);
  259.       }
  260.    }
  261.    GDS_putBlock(ddadr1x[0], ddadr1x[1], page, x, y, x+xsiz-1, y, PSET);
  262.    GDS_putBlock(ddadr2x[0], ddadr2x[1], page, x, y+ysiz-1, x+xsiz-1, y+ysiz-1, PSET);
  263.    GDS_putBlock(ddadr1y[0], ddadr1y[1], page, x, y+1, x, y+ysiz-2, PSET);
  264.    GDS_putBlock(ddadr2y[0], ddadr2y[1], page, x+xsiz-1, y+1, x+xsiz-1, y+ysiz-2, PSET);
  265.    *x0 = x; *y0 = y;
  266.    return;
  267. }
  268.  
  269.  
  270. void box(int x, int y)
  271. {
  272.      line(x, y, x+20, y, PSET, col15, 0, 0xffff);
  273.      line(x, y, x, y+20, PSET, col15, 0, 0xffff);
  274.      line(x, y+20, x+20, y+20, PSET, col8, 0, 0xffff);
  275.      line(x+20, y+20, x+20, y, PSET, col8, 0, 0xffff);
  276.      return;
  277. }
  278.  
  279. void box2(int x, int y)
  280. {
  281.      line(x, y, x+20, y, PSET, col8, 0, 0xffff);
  282.      line(x, y, x, y+20, PSET, col8, 0, 0xffff);
  283.      line(x, y+20, x+20, y+20, PSET, col15, 0, 0xffff);
  284.      line(x+20, y+20, x+20, y, PSET, col15, 0, 0xffff);
  285.      return;
  286. }
  287.  
  288. /* xy  check     return( yes=1, no=0 ) */
  289. int xychk(int x, int y, int x1, int y1, int x2, int y2)
  290. {
  291.     if (x1<=x && x<=x2 && y1<=y && y<=y2) return(1);
  292.     return(0);
  293. }
  294.  
  295. /* サブ・データ表示窓 */
  296. void subind(int x0, int y0, char *ch, int col)
  297. {
  298.    line(x0+105,y0+5,x0+115,y0+14, PSET, col1, 2, 0xffff);
  299.    line(x0+105,y0+5,x0+115,y0+14, PSET, col8, 1, 0xffff);
  300.    symbol(x0+107, y0+5, ch, 1,1, col,0,PSET);
  301. }
  302.  
  303. /*  calcu input area 0,0,114,139  */
  304. void  calcb(int x0, int y0)
  305. {
  306. int bcl[16];
  307. int xx,yy;
  308.    bcl[0] = col1;
  309.  
  310.    /* 影枠   影塗色 */
  311.    /* hatch(5); */
  312.    line(x0+10, y0+10, x0+139, y0+139, PSET, col0, 2, 0xffff);
  313.  
  314.    /* キーボード */
  315.    line(x0+0,y0+0,x0+130,y0+130,   PSET, col7, 2, 0xffff);
  316.    line(x0+0,y0+0,x0+130,y0+130,   PSET, col1, 1, 0xffff);
  317.    line(x0+130,y0+0,x0+133,y0+3,   PSET, col1, 0, 0xffff);
  318.    line(x0+133,y0+3,x0+133,y0+133, PSET, col1, 0, 0xffff);
  319.  /*  line(x0+133,y0+133,x0+130,y0+130, PSET, col1, 0, 0xffff); */
  320.    line(x0+133,y0+133,x0+3,y0+133, PSET, col1, 0, 0xffff);
  321.    line(x0+3,y0+133,x0+0,y0+130,   PSET, col1, 0, 0xffff);
  322.  
  323.    /*  キーボード外枠塗色 */
  324.    drmode(PSET);
  325.    paint(x0+131,y0+2,   1, col1,  1, bcl);
  326.    paint(x0+2,y0+131,   1, col1,  1, bcl);
  327.    paint(x0+131,y0+131, 1, col1,  1, bcl);
  328.  
  329.    /* データ表示窓 */
  330.    line(x0+5,y0+5,x0+100,y0+25, PSET, col1, 2, 0xffff);
  331.    line(x0+5,y0+5,x0+100,y0+25, PSET, col8, 1, 0xffff);
  332.    /* サブ・データ表示窓 */
  333.    line(x0+105,y0+5,x0+115,y0+14, PSET, col1, 2, 0xffff);
  334.    line(x0+105,y0+5,x0+115,y0+14, PSET, col8, 1, 0xffff);
  335.    /* test data   subind(x0, y0, "e", 10);  */
  336.    /* キー作成 */
  337.    xx=x0+105; yy=y0+16;
  338.    line(xx, yy, xx+20, yy, PSET, col15, 0, 0xffff);
  339.    line(xx, yy, xx, yy+9, PSET, col15, 0, 0xffff);
  340.    line(xx, yy+9, xx+20, yy+9, PSET, col8, 0, 0xffff);
  341.    line(xx+20, yy+9, xx+20, yy, PSET, col8, 0, 0xffff);
  342.    line(xx+1,yy+1,xx+19,yy+8, PSET, col15, 0, 0xffff);
  343.    line(xx+1,yy+8,xx+19,yy+1, PSET, col15, 0, 0xffff);
  344.    /*  symbol_(xx+2, yy+2, "終", 1,1, col15,0,PSET); */
  345.    xx=x0+5; yy=y0+30;
  346.    box(xx, yy);
  347.    symbol_(xx+2, yy+2, "7", 1,1, col15,0,PSET);
  348.    xx=x0+30; yy=y0+30;
  349.    box(xx, yy);
  350.    symbol_(xx+2, yy+2, "8", 1,1, col15,0,PSET);
  351.    xx=x0+55; yy=y0+30;
  352.    box(xx, yy);
  353.    symbol_(xx+2, yy+2, "9", 1,1, col15,0,PSET);
  354.    xx=x0+5;  yy=y0+55;
  355.    box(xx, yy);
  356.    symbol_(xx+2, yy+2, "4", 1,1, col15,0,PSET);
  357.    xx=x0+30; yy=y0+55;
  358.    box(xx, yy);
  359.    symbol_(xx+2, yy+2, "5", 1,1, col15,0,PSET);
  360.    xx=x0+55; yy=y0+55;
  361.    box(xx, yy);
  362.    symbol_(xx+2, yy+2, "6", 1,1, col15,0,PSET);
  363.    xx=x0+5;  yy=y0+80;
  364.    box(xx, yy);
  365.    symbol_(xx+2, yy+2, "1", 1,1, col15,0,PSET);
  366.    xx=x0+30; yy=y0+80;
  367.    box(xx, yy);
  368.    symbol_(xx+2, yy+2, "2", 1,1, col15,0,PSET);
  369.    xx=x0+55; yy=y0+80;
  370.    box(xx, yy);
  371.    symbol_(xx+2, yy+2, "3", 1,1, col15,0,PSET);
  372.    xx=x0+5;  yy=y0+105;
  373.    box(xx, yy);
  374.    symbol_(xx+2, yy+2, "0", 1,1, col15,0,PSET);
  375.    xx=x0+30; yy=y0+105;
  376.    box(xx, yy);
  377.    symbol_(xx+2+6, yy+2, ".", 1,1, col15,0,PSET);
  378.    xx=x0+80, yy=y0+30;
  379.    box(xx, yy);
  380.    symbol_(xx+2, yy+2, "÷", 1,1, col15,0,PSET);
  381.    xx=x0+80, yy=y0+55;
  382.    box(xx, yy);
  383.    symbol_(xx+2, yy+2, "×", 1,1, col15,0,PSET);
  384.    xx=x0+80, yy=y0+80;
  385.    box(xx, yy);
  386.    symbol_(xx+2, yy+2, "+", 1,1, col15,0,PSET);
  387.    xx=x0+80, yy=y0+105;
  388.    box(xx, yy);
  389.    symbol_(xx+2, yy+2, "-", 1,1, col15,0,PSET);
  390.    xx=x0+105, yy=y0+30;
  391.    box(xx, yy);
  392.    symbol_(xx+2, yy+2, "C", 1,1, col15,0,PSET);
  393.    xx=x0+105, yy=y0+55;
  394.    box(xx, yy);
  395.    symbol(xx+2, yy+2, "CE", 1,2, col15,0,PSET);
  396.    xx=x0+105, yy=y0+80;
  397.    box(xx, yy);
  398.    symbol_(xx+2, yy+2, "←", 1,1, col15,0,PSET);
  399.    xx=x0+105, yy=y0+105;
  400.    box(xx, yy);
  401.    symbol_(xx+2, yy+2, "√", 1,1, col15,0,PSET);
  402.    xx=x0+55, yy=y0+105;
  403.    box(xx, yy);
  404.    symbol_(xx+2, yy+2, "=", 1,1, col15,0,PSET);
  405.    return;
  406. }
  407.  
  408. void errind(int x0, int y0)
  409. {
  410.    subind(x0, y0, "e", col10);
  411. }
  412.  
  413. /* number indicate */
  414. void numind(int x0, int y0, char *nline)
  415. {
  416.    /* データ表示窓 */
  417.    line(x0+5,y0+5,x0+100,y0+25, PSET, col0, 2, 0xffff);
  418.    line(x0+5,y0+5,x0+100,y0+25, PSET, col1, 2, 0xffff);
  419.    line(x0+5,y0+5,x0+100,y0+25, PSET, col8, 1, 0xffff);
  420.    symbol(x0+8, y0+8,nline, 1, 2, col14, 0, PSET);
  421. }
  422.  
  423. /*  num check and print */
  424. int numin(int x, int y, int nn, char nline[], int *ncnt, int *pf, int *nf)
  425. {
  426.    if ((nn == '-' && *ncnt != 0) || (nn == '+') || (nn == 'x') || (nn == '/') || (nn == 'C') || (nn == 'c') || (nn == '=') || (nn == 'r')) {
  427.       return(0);
  428.    }
  429.    if ((nn != '<' && *ncnt == 11 && *nf == 1) || ( nn == '.' && *pf != 0 && *nf == 1)) {
  430.       putchar('\7'); return(0); /* error (but no error flag) */
  431.    }
  432.    if ( nn == '<' ) {
  433.       if (*ncnt == 0 || *nf == 0 || *nf == 2) {
  434.          putchar('\7'); /* error */
  435.          return(1);
  436.       } else {
  437.          (*ncnt)--;
  438.          symbol(x+8+8*(*ncnt),y+8,nline+(*ncnt), 1, 2, col1, 0, PSET);
  439.          if (nline[*ncnt] == '.') *pf = 0; /* flag clear */
  440.          nline[*ncnt] = '\0';
  441.          return(1);
  442.       }
  443.    }
  444.    if (*nf == 0 || *nf == 2) {
  445.       numind(x, y, "");
  446.       nline[0] = '\0';
  447.       *ncnt = 0;
  448.    }
  449.    if (nn == '.') *pf = 1; /* flag set */
  450.    nline[*ncnt] = nn;
  451.    nline[(*ncnt)+1] = '\0';
  452.    symbol(x+8+8*(*ncnt),y+8,nline+(*ncnt), 1, 2, col14, 0, PSET);
  453.    (*ncnt)++;
  454.    *nf = 1;
  455.    return(1);
  456. }
  457.  
  458. void calc2(int x, int y, int nn, double *ans, int *ope, char nline[], int *ncnt, int *pf, int *nf)
  459. {
  460.    char buf[2];
  461.    double ans2;
  462.    
  463.    mathern = 0; /* math error no. clear */
  464.    buf[1] = '\0';
  465.    if (nn != 'C') {
  466.       if (*nf == -1) return; /* error */
  467.    } else { /* error reset */
  468.       *nf = 0;  *ope = '+';
  469.       *ncnt = 0; *pf = 0;
  470.       nline[0] = '\0';
  471.       *ans = 0;
  472.       numind(x, y, "");
  473.       subind(x, y, "", col1);
  474.       return;
  475.    }
  476.    if (nn == 'c') {
  477.       *nf = 0;
  478.       *ncnt = 0; *pf = 0;
  479.       nline[0] = '\0';
  480.       numind(x, y, "");
  481.       return;
  482.    }
  483.    if (numin(x, y, nn, nline, ncnt, pf, nf) != 0) return;
  484.    buf[0] = nn;
  485.    if (nn == '/') {
  486.       subind(x, y, "-", col14);
  487.       symbol(x+107, y+5, ":", 1,1, col14,0,PSET);
  488.    } else {
  489.       if (nn != 'r') subind(x, y, buf, col14);
  490.    }
  491.    if ((nn != 'r') && (*nf != 2) && (*ncnt == 0 || *nf == 0)) {
  492.       *ope = nn;
  493.       return;
  494.    } else {
  495.       if (nn == 'r') {
  496.          ans2 = sqrt(atof(nline));
  497.          *nf = 2;
  498.       } else {
  499.          switch (*ope) {
  500.             case '+': *ans = *ans + atof(nline); break;
  501.             case '-': *ans = *ans - atof(nline); break;
  502.             case 'x': *ans = *ans * atof(nline); break;
  503.             case '/': *ans = *ans / atof(nline); break;
  504.             case '=': *ans = atof(nline);        break;
  505.             case 'c': nline[0] = '\0';
  506.                       *ncnt = 0;
  507.                       numind(x, y, "");
  508.                       break;
  509.          }
  510.          *ope = nn; /*  *ope = ope code */
  511.          *nf = 0; /* *nf = num flag if eqaul zero then not num */
  512.          ans2 = *ans;
  513.       }
  514.    }
  515. /*
  516.    for debug
  517.    printf("ope=%c nn= %c ans= %f nline= %s\n",*ope, nn, *ans, nline);
  518. */
  519.    if (fabs(ans2) > 9999999999) {
  520.       *nf = -1;
  521.       errind(x, y);
  522.    } else {
  523.       sprintf(nline, "%f\0", ans2);
  524.       nline[11] = '\0';
  525.       *ncnt = strlen(nline);
  526.       numind(x, y, nline);
  527.    }
  528.    if (mathern != 0) {
  529.       *nf = -1; /* if math error then error flag set */
  530.       errind(x, y);
  531.    }
  532.    return;
  533. }
  534.  
  535. /* mouse input                     */
  536. /* return = 0:not input,  1:input  */
  537. /* *pnum  = anser                  */
  538. int calc(int *px, int *py, double *pnum)
  539. {
  540.     int x, y, x2, y2, calflg=0;
  541.     int ncnt = 0, pf = 0, mx, my, nn, xw, yw, ope = '+', nf = 0; /* nf = 0, 1 , 2, -1 : (calc, num, sqrt, errflag) */
  542.     int i;
  543.     double  ans = 0;
  544.     char nline[24]; /* 12 */
  545.     unsigned  ddadr[2], ddadr2[2];
  546.     unsigned char page;
  547.     char      buf[9804], buf2[1641]; /* (140*140+7)/8*4,  (126*26+7)/8*4  */
  548.     
  549.     x = *px; y = *py;
  550.     
  551.     for (i=0; i <12; i++) nline[i]=0;
  552.     BSETDATAADR(ddadr, buf);
  553.     BSETDATAADR(ddadr2, buf2);
  554.  
  555. start:;
  556.     MOS_disp(1); /* mouse disp off */
  557.     page = 0;
  558.     GDS_getBlock(ddadr[0], ddadr[1], page, x, y, x+139, y+139);
  559.     calcb(x,y);
  560.     if (calflg != 0) {
  561.        GDS_putBlock(ddadr2[0], ddadr2[1], page, x, y, x+125, y+25, PSET);
  562.     }
  563.     calflg = 1;
  564.     MOS_horizon(x, x+130);
  565.     MOS_vertical(y, y+130);
  566.     MOS_disp(0); /* mouse disp on */
  567.     
  568.     while (1) {
  569.        nn = 0;
  570.        while ((MOS_rdpos(&mx, &my) & 0x01) == 0);
  571.        if (xychk(mx, my, x+115,y+5,x+125,y+15) == 1) {
  572.           page = 0;
  573.           x2 = x; y2 = y;
  574.           MOS_horizon(150, 610);
  575.           MOS_vertical(20, 250);
  576.           GDS_getBlock(ddadr2[0], ddadr2[1], page, x, y, x+125, y+25);
  577.           mcu2();
  578.           movbox(&x, &y, 131, 131, 120, 10);
  579.           mcu1();
  580.           GDS_putBlock(ddadr[0], ddadr[1], page, x2, y2, x2+139, y2+139, PSET);
  581.           goto start;
  582.           /*  all reset
  583.           GDS_getBlock(ddadr[0], ddadr[1], page, x, y, x+139, y+139);
  584.           GDS_putBlock(ddadr2[0], ddadr2[1], page, x, y, x+125, y+15, PSET);
  585.           MOS_horizon(x, x+130);
  586.           MOS_vertical(y, y+130);
  587.           continue;
  588.           */
  589.        }
  590.        for (i=1; i==1; i++) {
  591.           if (xychk(mx, my, xw=x+5, yw=y+30, x+25,  y+50) == 1)  { nn = '7'; break; }
  592.           if (xychk(mx, my, xw=x+30, yw=y+30, x+50, y+50) == 1)  { nn = '8'; break; }
  593.           if (xychk(mx, my, xw=x+55, yw=y+30, x+75, y+50) == 1)  { nn = '9'; break; }
  594.           if (xychk(mx, my, xw=x+5,  yw=y+55, x+25, y+75) == 1)  { nn = '4'; break; }
  595.           if (xychk(mx, my, xw=x+30, yw=y+55, x+50, y+75) == 1)  { nn = '5'; break; }
  596.           if (xychk(mx, my, xw=x+55, yw=y+55, x+75, y+75) == 1)  { nn = '6'; break; }
  597.           if (xychk(mx, my, xw=x+5,  yw=y+80, x+25,y+100) == 1)  { nn = '1'; break; }
  598.           if (xychk(mx, my, xw=x+30, yw=y+80, x+50,y+100) == 1)  { nn = '2'; break; }
  599.           if (xychk(mx, my, xw=x+55, yw=y+80, x+75,y+100) == 1)  { nn = '3'; break; }
  600.           if (xychk(mx, my, xw=x+5,  yw=y+105,x+25,y+125) == 1)  { nn = '0'; break; }
  601.           if (xychk(mx, my, xw=x+30, yw=y+105,x+50,y+125) == 1)  { nn = '.'; break; }
  602.           if (xychk(mx, my, xw=x+55, yw=y+105,x+75,y+125) == 1)  { nn = '='; break; }
  603.           if (xychk(mx, my, xw=x+80, yw=y+30, x+100,y+50) == 1)  { nn = '/'; break; }
  604.           if (xychk(mx, my, xw=x+80, yw=y+55, x+100,y+75) == 1)  { nn = 'x'; break; }
  605.           if (xychk(mx, my, xw=x+80, yw=y+80, x+100,y+100) == 1)  { nn = '+'; break; }
  606.           if (xychk(mx, my, xw=x+80, yw=y+105,x+100,y+125) == 1)  { nn = '-'; break; }
  607.           if (xychk(mx, my, xw=x+105,yw=y+30, x+125,y+50)  == 1)  { nn = 'C'; break; }
  608.           if (xychk(mx, my, xw=x+105,yw=y+55, x+125,y+75)  == 1)  { nn = 'c'; break; }
  609.           if (xychk(mx, my, xw=x+105,yw=y+80, x+125,y+100) == 1)  { nn = '<'; break; } /* back spase */
  610.           if (xychk(mx, my, xw=x+105,yw=y+105,x+125,y+125) == 1)  { nn = 'r'; break; }
  611.           xw = 0; yw = 0;
  612.        }
  613.        if (xychk(mx, my, x+105, y+16,x+125,y+25) == 1) {
  614.           xw=x+105; yw=y+16;
  615.           line(xw, yw, xw+20, yw, PSET, col8, 0, 0xffff);
  616.           line(xw, yw, xw, yw+9, PSET, col8, 0, 0xffff);
  617.           line(xw, yw+9, xw+20, yw+9, PSET, col15, 0, 0xffff);
  618.           line(xw+20, yw+9, xw+20, yw, PSET, col15, 0, 0xffff);
  619.           while ((MOS_rdpos(&mx, &my) & 0x01) == 1);
  620.           if (xychk(mx, my, x+105, y+16,x+125,y+25) != 1) {
  621.              line(xw, yw, xw+20, yw, PSET, col15, 0, 0xffff);
  622.              line(xw, yw, xw, yw+9, PSET, col15, 0, 0xffff);
  623.              line(xw, yw+9, xw+20, yw+9, PSET, col8, 0, 0xffff);
  624.              line(xw+20, yw+9, xw+20, yw, PSET, col8, 0, 0xffff);
  625.              continue;
  626.           } else {
  627.              MOS_horizon(0,  639);
  628.              MOS_vertical(0, 399);
  629.              GDS_putBlock(ddadr[0], ddadr[1], page, x, y, x+139, y+139, PSET);
  630.              *px = x; *py = y;
  631.              if (nline[0] == '\0') {
  632.                 *pnum = 0;
  633.                 return(0);
  634.              } else {
  635.                 *pnum = atof(nline);
  636.                 return(1);
  637.              }
  638.           }
  639.        } else {
  640.           if (xw != 0) box2(xw, yw);
  641.           if (nn != 0) calc2(x, y, nn, &ans, &ope, nline, &ncnt, &pf, &nf);
  642.           else putchar('\7');
  643.           while ((MOS_rdpos(&mx, &my) & 0x01) == 1);
  644.           if (xw != 0) box(xw, yw);
  645.        }
  646.     }
  647. }
  648.  
  649. /* end of file */
  650.